﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CSP.Common.Web;

namespace CSP.Web.UserControls
{
    public partial class CSPDatePicker : CSPUserControlBase
    {
        public string Style
        {
            set
            {
                this.Txt_DatePicker.Attributes.Add("style", value);
            }

        }

        public string Class
        {
            set;
            get;


        }

        /// <summary>
        /// 日期文本的值
        /// </summary>
        public string Text
        {
            get
            {
                return this.Txt_DatePicker.Value;
            }
            set
            {
                this.Txt_DatePicker.Value = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //this.Txt_DatePicker.ID = this.Txt_DatePicker.ClientID;
            InitClass(this.Txt_DatePicker.ClientID);
        }

        protected void InitClass(string clientId)
        {
            if (string.IsNullOrEmpty(Class))
            {
                return;
            }
            int indexStart = Class.IndexOf("[");
            int indexEnd = Class.IndexOf("]");
            string classValue = Class;
            if (indexStart != -1 && indexEnd != -1)
            {
                string replacedValue = Class.Substring(indexStart, indexEnd - indexStart + 1);//被替换的值
                string newValue = this.Txt_DatePicker.ClientID.Replace(this.ID, replacedValue.Substring(1, replacedValue.Length - 2));
                classValue = Class.Replace(replacedValue, newValue);
            }

            this.Txt_DatePicker.Attributes.Add("class", classValue);
        }
    }
}